let fs = require('mz/fs');
let path = require('path');

// function mkdir (url, cb) {
//     let arr = url.split('/');
//     let index = 0;
//     function next () {
//         if (index === arr.length) return cb();
//         let path = arr.slice(0, ++index).join('/');
//         fs.access(path).then((res) => {
//             next()
//         }, (err) => {
//             fs.mkdir(path).then(() => {
//                 next()
//             }, () => {})
//         })
//     }
//     next();
// }

async function mkdir (url) {
    let arr = url.split('/');
    for (let i in arr) {
        let currentPath = arr.slice(0, +i + 1).join('/');
        try {
            await fs.access(currentPath)
        } catch(e) {
            await fs.mkdir(currentPath)
        }
    }
}

mkdir('a/b/q').then(() => {
    mkdir('a/d/p')
})



// mkdir('a/d/q', () => {
//     console.log('创建成功');
// })


